package Work5;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		PersonSortable[] personlist = new PersonSortable[n];
		for (int i = 0; i < personlist.length; i++) {
			String name = in.next();
			int age = in.nextInt();
			personlist[i] = new PersonSortable(name,age);
		}
		Arrays.sort(personlist);
		for(PersonSortable per : personlist){
			System.out.println(per);
		}
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));
	}

}
class PersonSortable implements Comparable{
	private String name;
	private int age;
	public PersonSortable(String name, int age) {
		this.name = name;
		this.age = age;
	}
	
	@Override
	public String toString() {
		return this.name + "-" + this.age;
	}

	@Override
	public int compareTo(Object o) {
		if(o instanceof PersonSortable){
			o = (PersonSortable) o;
			if(!this.name.equals(((PersonSortable) o).name)){
				if(this.name.compareTo(((PersonSortable) o).name) > 0)return 1;
				else return -1;
			}
			else if( !(this.age == ((PersonSortable)o).age)){
				if(this.age >((PersonSortable)o).age)return 1;
				else return -1;
			}
			return 0;
		}
		
		return 0;
	}
	
}